<!-- @Author: Yu_Bo -->
<template>
	<view class="address">
		<view class="list" v-for="(item, index) in list" :key="index" @click="detailsBtn(item)">
			<image class="left_icon" src="@/static/images/img/address.png" mode=""></image>
			<view class="list_info">
				<view class="info_top">
					<text class="name">{{item.name}} {{item.phone}}</text>
					<text class="tip_a" v-if="item.isdefault == 1">默认</text>
					<text class="tip_b" v-if="item.isschool == 0">学校</text>
				</view>
				<view class="info_bot line_one" v-if="item.isschool == 0">
					{{item.building}}
					{{item.chamber}}
				</view>
				<view class="info_bot line_one" v-else>
					{{item.Area.province}}
					{{item.Area.city}}
					{{item.Area.region}}
					{{item.detail}}
				</view>
			</view>
			<image class="right_icon" src="@/static/images/img/right_icon.png" mode=""></image>
		</view>
		<!-- 无数据 -->
		<c-emptydata :type="2" v-if="list.length == 0"></c-emptydata>
		<!-- 底部按钮 -->
		<c-footer>
			<view class="footer_btn">
				<view class="btn_txt color_right page_button" @click="addBtn">
					新增地址
				</view>
			</view>
		</c-footer>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return{
				type: null,
				list: []
			}
		},
		computed: {},
		onLoad(opt) {
			if(opt.type) {
				this.type = opt.type
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			// 获取列表
			getList() {
				var that = this
				that.$httpApi.addressList().then((res) => {
					if (res.code == 1) {
						that.list = res.data
					}
				})
			},
			// 地址添加编辑
			detailsBtn(info) {
				if(this.type == 1) {
					let pages = getCurrentPages();  //获取所有页面栈实例列表
					let nowPage = pages[ pages.length - 1];  //当前页页面实例
					let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
					prevPage.$vm.address={
						address_id: info.address_id,
						isschool: info.isschool,
						name: info.name,
						phone: info.phone,
						province: info.Area?.province || "",
						city: info.Area?.city || "",
						region: info.Area?.region || "",
						detail: info.detail || "",
						building: info.building || "",
						chamber: info.chamber || "",
					}
					uni.navigateBack();
					return
				} else {
					this.$navTo("/pagesWo/address/addedit?id="+info?.address_id || "")
				}
			},
			addBtn() {
				this.$navTo("/pagesWo/address/addedit")
			}
		},
	}
</script>

<style lang='scss' scoped>
	.address {
		width: 100%;
		padding: 30rpx;
		min-height: 100vh;
		background: #F6F6F6;
		
		.list {
			width: 100%;
			padding: 30rpx 20rpx;
			background: #ffffff;
			margin-bottom: 30rpx;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			
			.left_icon {
				display: block;
				width: 42rpx;
				height: 42rpx;
			}
			
			.list_info {
				width: 578rpx;
				padding: 0 20rpx;
				
				.info_top {
					width: 100%;
					display: flex;
					align-items: center;
					
					.name {
						margin-right: 20rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 30rpx;
						color: #333333;
					}
					
					.tip_a {
						margin-left: 10rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 20rpx;
						color: #5A68FF;
						padding: 2rpx 8rpx;
						background: #E9EBFF;
						border-radius: 8rpx;
						border: 2rpx solid #5A68FF;
					}
					
					.tip_b {
						margin-left: 10rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 20rpx;
						color: #FF9400;
						padding: 2rpx 8rpx;
						background: #FFF4E4;
						border-radius: 8rpx;
						border: 2rpx solid #FF9400;
					}
				}
				
				.info_bot {
					width: 100%;
					padding-top: 10rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #999999;
				}
			}
			
			.right_icon {
				display: block;
				width: 30rpx;
				height: 30rpx;
			}
		}
		
		.list:last-child {
			margin-bottom: 0;
		}
	}
	
	.footer_btn {
		width: 100%;
		padding: 30rpx 30rpx;
		background: #fff;
		
		.btn_txt {
			width: 100%;
			height: 90rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			border-radius: 45rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>